import { defineStore } from 'pinia'

import { ref } from 'vue'
import { cleanSession } from "@/utils/auth"
// 设计一个缓存 取色器

export const useUserInfoStore = defineStore('useUserInfoStoreName', () => {
    const userInfo = ref<any>()
    const token = ref("")
    const setUserInfo = (item: any) => {
        userInfo.value = item
        token.value = item.token
    }

    const clearUserInfo = () => {
        cleanSession()
        token.value = ""
        userInfo.value = null
    }
    return {
        userInfo,
        setUserInfo,
        clearUserInfo
    }
},
    {
        persist: {
            storage: sessionStorage,
            paths: ['userInfo'],
        },
    })

